#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
const int mod=998244353;
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    
    int t;
    cin >> t;
    while(t--)
    {
    	string a;
    	int b;
    	cin >> a >> b;
		int n=a.size();

		int sum=0;
		for(int i=0;i<n;i++)
		{
			sum=sum+a[i]-48;
		}
	    //cout << sum << endl;
	    
	    if(sum>b)
	    {
	    	vector <int> c;
	    int x=n-1;
	    while(a[x]=='0')
	    {
	    	x--;
	    	c.push_back(0);
		}
        c.push_back(10-a[x]+48);
        sum=sum-a[x]+1+48;
       //cout << sum << endl;
        
        int z=x-1;
	    while(sum>b&&z>=0)
	    {
	    	c.push_back(9-a[z]+48);
	    	sum=sum-a[z]+48;
			z--;
	    }
	    for(int i=c.size()-1;i>=0;i--)
	    {
	    	cout << c[i];
		}
		cout << endl;
		}
		else
		{
			cout << "0" << endl;
		}
	}
    return 0;
}
